package com.pnnd;

import com.pnnd.utils.NeedInit;

import java.util.*;

public class NdEnvironment {

    static Map<String,DTypeObject> nameDTypeMap;

    static Map<String,DTypeObject> baseTypeStrDTypeMap;

    static Map<Class,DTypeObject> classDTypeObjectMap;

    static Class[] baseClass = new Class[]{int.class,long.class,double.class,
            short.class,float.class,boolean.class,
            char.class,String.class,Integer.class,Long.class,Double.class,Float.class,Short.class,
            Boolean.class,Character.class
    };

    static{
        nameDTypeMap = new HashMap<>();
        baseTypeStrDTypeMap = new HashMap<>();
        classDTypeObjectMap = new HashMap<>();

        List<NeedInit> needInitList = new ArrayList<>();

        // TODO 扫描包加载所有待初始化对象

        for(NeedInit needInit:needInitList){
            needInit.init();
        }
    }

    public static DTypeObject getByName(String name){
        return nameDTypeMap.get(name);
    }

    public static DTypeObject getByJvmClass(Class klass){
        if(Arrays.binarySearch(baseClass,klass) > -1){
            return nameDTypeMap.get(klass.getName().toLowerCase());
        }

        return classDTypeObjectMap.get(klass);
    }

    public static DTypeObject getByTypeStr(String typeStr){
        return baseTypeStrDTypeMap.get(typeStr);
    }

    private NdEnvironment(){

    }

    public void init(){

    }
}
